package com.kkwrite.regimen.provider.controller.spokesman;

import java.util.List;

import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kkwrite.regimen.common.entity.dto.OutDTO;
import com.kkwrite.regimen.common.entity.dto.spokesman.SpokesmanDTO;
import com.kkwrite.regimen.provider.exception.ServiceException;
import com.kkwrite.regimen.provider.service.spokesman.SpokesmanService;

/** 
 * 项目用户代言
 *
 * @author jinying
 */
@RestController
@RequestMapping("/spokesman")
public class SpokesmanController {

	private static final Logger logger = LoggerFactory.getLogger(SpokesmanController.class);
	
	@Resource(name = "spokesmanService")
	private SpokesmanService spokesmanService;
	
	@GetMapping("/getSpokesman/{itemId}")
	public OutDTO<List<SpokesmanDTO>> getSpokesman(@PathVariable Long itemId) {
		if (logger.isDebugEnabled()) {
			logger.debug("SpokesmanController.getSpokesman(), itemId = {}", itemId);	
		}
		
		OutDTO<List<SpokesmanDTO>> outDTO = new OutDTO<>();
		try {
			List<SpokesmanDTO> spokesmanDTOList = spokesmanService.querySpokesman(itemId);
			outDTO.setSuccess("true");
			outDTO.setData(spokesmanDTOList);
			
			return outDTO;
		} catch (ServiceException e) {
			e.printStackTrace();
			
			return new OutDTO<List<SpokesmanDTO>>("failed", e.getMessage());
		}
	}
	
}
